//
//  BaseTableViewHeaderFooterView.m
//  乡易秀商户端
//
//  Created by delicious on 17/8/30.
//  Copyright © 2017年 chen. All rights reserved.
//

#import "BaseTableViewHeaderFooterView.h"
#import <objc/runtime.h>
#import "UIView+Base.h"
const char * ksection;


@implementation BaseTableViewHeaderFooterView
- (void)dealloc
{
    NSLog(@"%@ 这个类被强暴了",NSStringFromClass([self class]));
}

- (id)initWithViewController:(UIViewController *)ViewController reuseIdentifier:(NSString *)reuseIdentifier  forDataSource:(id)dataSource AtSection:(NSInteger)section
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        self.opaque = YES;
        [self onAsInitAddView:self.contentView forViewController:ViewController forDataSource:dataSource AtSection:section];
    }
    return self;
}


-(UIImageView *)imageView
{
    if (!_imageView) {
        UIImageView *imagev = ({
            UIImageView*l=[ UIImageView new];
            [self.contentView addV:l];
            l;
        });
        _imageView = imagev;
    }
    return _imageView;
    
}
-(HLTextField *)textField
{
    if (!_textField) {
        
        HLTextField*textF = ({
            HLTextField*l=[ HLTextField new];
            [self.contentView addV:l];
            l;
        });
        _textField = textF;
        
        
    }
    return _textField;
}

-(HLTextView *)textView
{
    if (!_textView) {
        HLTextView*textV = ({
            HLTextView*l=[ HLTextView new];
            [self.contentView addV:l];
            l;
        });
        _textView = textV;
        
    }
    return _textView;
}

-(UIButton *)button
{
    if (!_button) {
        UIButton *button = ({
            UIButton *l= [UIButton buttonWithType:UIButtonTypeCustom];
            [self.contentView addV:l];
            l;
        });
        _button = button;
    }
    return _button;
}



-(void)layoutSubviews
{
    [super layoutSubviews];
    CGRect frame = self.frame;
    if (self.layoutBlock) {
        self.layoutBlock(self,frame.origin,frame.size,self.center);
    }
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end


@implementation UITableViewHeaderFooterView (OF)



-(void)onAsInitAddView:(UIView *)view forViewController:(UIViewController *)ViewController forDataSource:(id)dataSource AtSection:(NSInteger)section
{
    
}

- (void)update:(id)model forTableView:(UITableView *)tableView AtSection:(NSInteger)section
{
    
}
-(void)setBackgroundColor:(UIColor *)backgroundColor
{
    self.contentView.backgroundColor = backgroundColor;
}


-(void)setSection:(NSInteger)section{
    objc_setAssociatedObject(self, &ksection,@(section), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
}
-(NSInteger)section{
    NSNumber *number = objc_getAssociatedObject(self, &ksection);
    return  [number integerValue];
}

-(void)onTextForBlock:(void (^)(NSString *, id, id, NSIndexPath *, id))blcok
{
    if (self.textBlcok != blcok) {
        self.textBlcok = blcok;
    }
}


- (void)onButtonForBlock:(void (^)(id, id, NSIndexPath *, id))blcok
{
    if (self.buttonBlcok != blcok) {
        self.buttonBlcok = blcok;
    }
}

@end
